package num3;

import java.util.HashSet;

/**
 * @author : DuJiabao
 * @Project : sword-finger-offer
 * @Time : 2021/5/9 1:42
 * @Desc :
 */
public class Solution {
  public int lengthOfLongestSubstring(String s) {
    HashSet<Character> set = new HashSet<>();
    int max = 0;
    int point = 0;  // 每次滑动窗口移动之后
    int length = s.length();
    for (int i = 0; i < length; i++) {
      while (point < length && !set.contains(s.charAt(point))) {
        set.add(s.charAt(point++)); // 每更新一个char，就移动一小格,在set中增加一个char
      }
      max = Math.max(max, set.size());  // 更新一下当前滑动窗口最大的长度
      set.remove(s.charAt(i));
    }
    return max;
  }

  public static void main(String[] args) {
    int res = new Solution().lengthOfLongestSubstring("abcac");
    System.out.println(res);
  }
}
